//
//  CurrencyTypeList.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/11.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "CurrencyTypeList.h"

CurrencyTypeList::CurrencyTypeList()
{
}

CurrencyTypeList::CurrencyTypeList( PGresult* result )
{
	int row = PQntuples( result );
	int column = PQnfields( result );
	for ( int i = 0; i < row; i++ ) 
	{
		std::vector< const char* > values( column );
		for ( int j = 0; j < column; j++ )
		{
			values[ j ] = PQgetvalue( result, i, j );
		}
		CurrencyType type( values );
		at( i ) = type;
	}
}
	
NSString* CurrencyTypeList::queryInsertStatement() const
{
	NSMutableString* sql = [ NSMutableString string ];
	[ sql appendFormat: @"insert into %@ values\n", CurrencyType::tableName() ];
	BOOL firstValue = YES;
	for ( int i = 0, count = size(); i < count; i++ )
	{
		const CurrencyType& value = at( i );
		if ( firstValue )
		{
			firstValue = NO;
		}
		else
		{
			[ sql appendString: @", " ];
		}
		[ sql appendFormat: @"%@\n", value.queryInsertValue() ];
	}
	[ sql appendString: @";\n" ];	
	return sql;
}
